import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'tradeAnalysisNewM',

  state: {
    timeData: [],
  },
  effects: {
    // 交易复盘-指标结果
    *getTradeIndicatorData({ payload, callback }, { call, put }) {
      const response = yield call(api.tradeAnalysisNew.getTradeIndicatorData, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data || []);
        } else {
          callback('fail');
          message.error(response.msg || '获取指标结果数据失败!');
        }
      } else {
        callback('fail');
        message.error('获取指标结果数据失败!');
      }
    },
    // 交易复盘-K线图
    *getKLineData({ payload, callback }, { call, put }) {
      const response = yield call(api.tradeAnalysisNew.getKLineData, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data || []);
        } else {
          callback('fail');
          message.error(response.msg || '获取K线图数据失败!');
        }
      } else {
        callback('fail');
        message.error('获取K线图数据失败!');
      }
    },

    //获取交易统计信息
    *getTradeCount({ payload, callback }, { call, put }) {
      const response = yield call(api.tradeAnalysisNew.getTradeCount, payload);

      if (response && response.code === 0) {
        callback(response.data);
      } else {
        callback();
        message.error((response && response.msg) || '获取交易统计信息失败');
      }
    },

    *getUnusualFluctuation({ payload, callback }, { call, put }) {
      const response = yield call(api.tradeAnalysisNew.getUnusualFluctuation, payload);
      if (response && response.code === 0) {
        callback(response.data);
      } else {
        callback();
        message.error((response && response.msg) || '获取市场异动信息失败');
      }
    },

    *getTradeDetail({ payload, callback }, { call, put }) {
      const response = yield call(api.tradeAnalysisNew.getTradeDetail, payload);

      if (response && response.code === 0) {
        callback(response.data);
      } else {
        callback();
        message.error((response && response.msg) || '获取交易明细信息失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
